package com.zw.access.service.impl;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zw.object.access.AccessReturn;
import com.zw.access.mapper.AccessReturnMapper;
import com.zw.access.service.AccessReturnService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zw.object.result.Result;
import com.zw.object.vo.AccessRegisterVo;
import com.zw.object.vo.AccessReturnVo;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 未归用户表 服务实现类
 * </p>
 *
 * @author zw
 * @since 2023-03-12
 */
@Service
public class AccessReturnServiceImpl extends ServiceImpl<AccessReturnMapper, AccessReturn> implements AccessReturnService {

    @Override
    public Result returnPage(AccessReturnVo vo) {
        Page<AccessReturn> page = new Page<>(vo.getPageNum(), vo.getPageSize());
        LambdaQueryWrapper<AccessReturn> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(StrUtil.isNotBlank(vo.getName()), AccessReturn::getName, vo.getName());
        wrapper.like(StrUtil.isNotBlank(vo.getDept()), AccessReturn::getDept, vo.getDept());
        if (StrUtil.isNotBlank(vo.getStart()) && StrUtil.isNotBlank(vo.getEnd())){
            DateTime a = DateUtil.parse(vo.getStart() + " 00:00:00", "yyyy-MM-dd HH:mm:ss");
            DateTime b = DateUtil.parse(vo.getEnd() + " 23:59:59", "yyyy-MM-dd HH:mm:ss");
            wrapper.between(AccessReturn::getCreateTime, a, b);
        }
        wrapper.orderByDesc(AccessReturn::getCreateTime);
        Page<AccessReturn> returnPage = baseMapper.selectPage(page, wrapper);
        return Result.ok(returnPage);
    }
}
